//
//  CommentVC.swift
//  ShareUmbrella
//
//  Created by niupark on 2017/9/9.
//  Copyright © 2017年 尧尚信息科技. All rights reserved.
//

import UIKit
import YSKit

class CommentVC: YSBaseViewController {
    
    let tableView = UITableView(frame: .zero, style: .plain)
    let myButton = UIButton()
    let otherButton = UIButton()
    override func setup() {
        super.setup()
    }
    /*
     *
     * 界面布局初始化
     */
    override func buildUI() {
        super.buildUI()
        self.title = I18n("VC.comment.title")
       let view1 =  UIView().ys.customize { (view) in
            self.view.addSubview(view)
            view.backgroundColor =  UIColor(red: 0xF3 / 255.0, green: 0xF3 / 255.0, blue: 0xF3 / 255.0, alpha: 1)
            view.snp.makeConstraints({ (make) in
                make.leading.top.trailing.equalTo(self.view)
                make.height.equalTo(100)
            })
        }
        self.tableView.ys.customize { (view) in
            self.view.addSubview(view)
            view.delegate = self
            view.dataSource = self
            view.separatorStyle = .none
            view.ys.register(CommentTableViewCell.self)
            view.snp.makeConstraints({ (make) in
                make.top.equalTo(view1.snp.bottom)
                make.leading.trailing.bottom.equalTo(self.view)
            })
        }
        
       let imageView = UIImageView().ys.customize { (view) in
            self.view.addSubview(view)
            view.image = UIImage(named: "抬头评论框")
            view.snp.makeConstraints({ (make) in
                make.top.equalTo(30)
                make.centerX.equalTo(self.view)
//                make.height.equalTo(45)
//                make.leading.equalTo(self.view).offset(20)
//                make.trailing.equalTo(self.view).offset(-20)

            })
        }
        
        self.myButton.ys.customize { (view) in
            self.view.addSubview(view)
            view.setBackgroundImage(UIImage(named: "选中框"), for: .selected)
            view.setTitle(I18n("VC.comment.mine.title"), for: .normal)
            view.setTitleColor(.black, for: .normal)
            view.isSelected = true
            view.snp.makeConstraints({ (make) in
                make.leading.centerY.equalTo(imageView)
                make.width.equalTo(imageView).dividedBy(2)
                make.height.equalTo(imageView)

            })
        }
        self.otherButton.ys.customize { (view) in
            self.view.addSubview(view)
            view.setBackgroundImage(UIImage(named: "选中框"), for: .selected)
            view.setTitle(I18n("VC.comment.other.title"), for: .normal)
            view.setTitleColor(.black, for: .normal)
            view.snp.makeConstraints({ (make) in
                make.trailing.centerY.equalTo(imageView)
                make.width.equalTo(imageView).dividedBy(2)
                make.height.equalTo(imageView)

            })
        }

    }
    
    override func buildRx() {
        super.buildRx()
        
        _ = self.myButton.rx.tap
            .takeUntil(self.rx.deallocated)
            .subscribe(onNext: { [weak self](RxGestureTypeOptions) in
                
                guard let `self` = self else {
                    return
                }
                self.myButton.isSelected = true
                self.otherButton.isSelected = false
            })
        
        _ = self.otherButton.rx.tap
            .takeUntil(self.rx.deallocated)
            .subscribe(onNext: { [weak self](RxGestureTypeOptions) in
                
                guard let `self` = self else {
                    return
                }
                self.myButton.isSelected = false
                self.otherButton.isSelected = true

            })
    }

    
}

extension CommentVC: UITableViewDelegate, UITableViewDataSource{
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: CommentTableViewCell.className(), for: indexPath) as! CommentTableViewCell
        return cell
    }

    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 120.0
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 12
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    }
}

